package com.situ.mapper;

import com.situ.bean.Attendance;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

public interface AttendanceMapper {
    @Delete({
        "delete from attendance",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into attendance (id, staff_id, ",
        "start, end, ",
        "length, type)",
        "values (#{id,jdbcType=INTEGER}, #{staffId,jdbcType=INTEGER}, ",
        "#{start,jdbcType=TIMESTAMP}, #{end,jdbcType=TIMESTAMP}, ",
        "#{length,jdbcType=INTEGER}, #{type,jdbcType=INTEGER})"
    })
    int insert(Attendance record);

    @Select({
        "select",
        "id, staff_id, start, end, length, type",
        "from attendance",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="staff_id", property="staffId", jdbcType=JdbcType.INTEGER),
        @Result(column="start", property="start", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="end", property="end", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="length", property="length", jdbcType=JdbcType.INTEGER),
        @Result(column="type", property="type", jdbcType=JdbcType.INTEGER)
    })
    Attendance selectByPrimaryKey(Integer id);

    @Select({
        "select",
        "id, staff_id, start, end, length, type",
        "from attendance"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="staff_id", property="staffId", jdbcType=JdbcType.INTEGER),
        @Result(column="start", property="start", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="end", property="end", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="length", property="length", jdbcType=JdbcType.INTEGER),
        @Result(column="type", property="type", jdbcType=JdbcType.INTEGER)
    })
    List<Attendance> selectAll();

    @Update({
        "update attendance",
        "set staff_id = #{staffId,jdbcType=INTEGER},",
          "start = #{start,jdbcType=TIMESTAMP},",
          "end = #{end,jdbcType=TIMESTAMP},",
          "length = #{length,jdbcType=INTEGER},",
          "type = #{type,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Attendance record);
}